﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Baik;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Baik.Interface.Execution;
using Baik.Interface.Expression;

namespace Tester
{
    [TestClass]
    public class EvalTest
    {
        public BaikInstance Instance = new BaikInstance();

        [TestMethod]
        public void Given_ObjectLiteral_When_Evaluate_Then_Return_IObject_With_Members()
        {

            var obj = Instance.Evaluate("{test:(){return true;};};");
            var funobj = obj.Get("test");
            Assert.IsTrue(funobj is IFunction);
            var rslt =  (funobj as IFunction).Call(new IObject[] {});
            Assert.IsTrue(rslt is Baik.Interface.Execution.ITrue);
        }
        [TestMethod]
        public void Given_ObjectLiteral_Duplicate_assignments_When_Evaluate_Then_Return_IObject_With_Last_Assignment()
        {
            var obj = Instance.Evaluate("{test:(){return false;};test:(){return true;};value:test();};");
            var funobj = obj.Get("test");
            var rtnval = obj.Get("value");
            Assert.IsTrue(funobj is IFunction);
            var rslt = (funobj as IFunction).Call(new IObject[] {});
            Assert.IsTrue(rslt is Baik.Interface.Execution.ITrue);
        }
        [TestMethod]
        public void Given_ObjectLiteral_Call_Function_Litteral_Assign_Variable_When_Evaluate_Then_Return_IObject_With_Value_Established_By_Execution()
        {
            var obj = Instance.Evaluate("{value:(){return true;}();};");
            var rtnval = obj.Get("value");
            Assert.IsTrue(rtnval is Baik.Interface.Execution.ITrue);
        }

        [TestMethod]
        public void Given_ArrayLiteral_When_Access_Via_Valid_idex_Then_Item_at_index()
        {
            var obj = Instance.Evaluate("{arr:[true];value:arr[0];}");
            var rtnval = obj.Get("value");
            Assert.IsTrue(rtnval is Baik.Interface.Execution.ITrue);
        }
    }
}
